/**
 * This class implements the barber's part of the
 * Barbershop thread synchronization example.
 */
public class Barber implements Runnable{
	/**
	 * Creates a new barber.
	 * @param gui		The GUI.
	 * @param pos		The position of this barber's chair
	 */
	private Gui gui;
	private int pos;
	
	
	public Barber(Gui gui, int pos) { 
		this.pos = pos;
		this.gui = gui;
		// Incomplete
	}

	/**
	 * Starts the barber running as a separate thread.
	 */
	public void startThread() {
		run();
		// Incomplete
	}

	public void run(){
		
		while(true){
			Customer customer;
			
				customer = BarbershopGui.queue.removeCustomer();
				
				if(customer != null){
					gui.emptyLoungeChair(customer.chairNumber);
					gui.fillBarberChair(pos, customer);
					gui.println("Barber is working");
					gui.barberIsAwake(pos);
					try {
					Thread.sleep(Globals.barberSleep);
					gui.emptyBarberChair(pos);
					gui.barberIsSleeping(pos);
					gui.println("Barber is sleeping");
					Thread.sleep((long) (Globals.barberSleep*Math.random()));
					} catch (InterruptedException e) {
						System.out.println(e);
					}
				}else{
					gui.println("Barber is waiting for customer");
					try {
						Thread.sleep(Globals.barberSleep);
					} catch (InterruptedException e) {
						e.printStackTrace();
					}
				}
			
		}
	}
	
	
	/**
	 * Stops the barber thread.
	 */
	public void stopThread() {
		// Incomplete
	}

	// Add more methods as needed
}

